﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LinkViewer
{
    /// <summary>
    /// Interaction logic for DisplayBrowser.xaml
    /// </summary>
    public partial class DisplayBrowser : Window
    {
        string _html;
        string _url;
        public DisplayBrowser(string html, string title, string url)
        {
            InitializeComponent();
            _html = html;
            this.Title = title;
            _url = url;
            browser.Loaded += new RoutedEventHandler(browser_Loaded);
            browser.BeginNavigation += new EventHandler<Cjc.ChromiumBrowser.WebBrowser.UrlEventArgs>(browser_BeginNavigation);
            browser.FinishLoading += new EventHandler(browser_FinishLoading);
        }

        void browser_FinishLoading(object sender, EventArgs e)
        {
            //hacky way of doing it, but trying to get it so the webpage never leaves, instead when a link is clicked it opens a new window
            if (browser.Source != _url)
            {
                browser.Source = _url;
                browser.LoadHtml("<html><head></head><body>" + _html + "</body></html>");
            }
               
        }

        void browser_BeginNavigation(object sender, Cjc.ChromiumBrowser.WebBrowser.UrlEventArgs e)
        {
        
            try
            {
                
               
                if (!e.Url.Contains("Known%20Issues"))
                    System.Diagnostics.Process.Start(e.Url);
                
            }
            catch
            { }
        }

        void browser_Loaded(object sender, RoutedEventArgs e)
        {
            browser.LoadHtml("<html><head></head><body>" + _html + "</body></html>");
        }
    }
}
